Merge pull request #11834 from ctzsnooze/GPS_Refactor_plus_120hz
[betaflight.git] / docs / EXST bootloader.md
blob466f5c82eb77d49b56e93238be81b82572826c7e
1 # EXST bootloader
3 The EXST (External Storage) system requires that the targets' CPU has a small program, called a bootloader, that provides functionality to load firmware from an external storage into the CPU's RAM so that the firmware can be executed.
5 Example external storage systems include:
6 * External Flash using Firmware Partition
7 * File on an SD card.
9 EXST targets also have the requirement of providing a mechansim to load and save configuration ('eeprom').  options for this include:
11 * CPU Embedded flash page.
12 * External Flash using Config Partition
13 * File on an SD card.
15 Since external storage systems can become corrupted, and communication errors can occur, Bootloaders should verify correct loading of the firmware from an external storage system, or after transferring via a debugger.  An hash is provided for this purpose.
17 Bootloaders are not limited to just one storage system. 
19 Bootloaders may offer additional functionality, such as:
20 * a means to update the firmware on an external storage medium (e.g. via DFU)
21 * update one external storage system from another (i.e. update external flash from file on SD card)
22 * backup, select, swap or erase firmware
23 * backup, select, swap or erase configuration.
25 Users should consult the manual that came with their EXST bootloader-equipped flight controller for details on how to use any such features.
27 The build system provides a way to build files suitable for transferring onto an external storage medium via the standard 'bin'/'hex' make goals.
29 ```
30 make TARGET=<targetname>
31 ```
33 This results in the usual `*.bin` and `*.hex` files and also a `*_EXST.elf` file which have been patched to contain information required for bootloader operation.
35 The `.bin` file is a binary file which should be transferred to the storage medium and is suitable for distribution.
36 The `.hex` file is a hex file which can be used by tools for uploading to a bootloader and is suitable for distribution.
38 For developers there is a `_EXST.elf` file which is a standard `.elf` file that has had one section replaced, this file is suitable for uploading to targets using a debugger such as GDB.
40 For details on the memory sections used refer to the linker files.
42 ## EXST format
44 The format for EXST targets is as follows:
46 * Firmware.
47 * Bootloader block.
49 The bootloader block is 64 bytes.
51 For example a 448K EXST `.bin` file is comprised as follows:
53 | Start Address | End address | Usage            |
54 | ------------- | ----------- | ---------------- |
55 | 0x00000       | 0x6FFBF     | Firmware section |
56 | 0x6FFC0       | 0x6FFFF     | Bootloader block |
59 ## EXST bootloader block
61 The bootloader block is comprised as follows:
64 | Start Address | End address | Usage            |
65 | ------------- | ----------- | ---------------- |
66 | 0x00          | 0x00        | Block Format     |
67 | 0x01          | 0x3F        | Block Content    |
69 Block Formats
71 | Value | Meaning           |
72 | ----- | ----------------- |
73 | 0x00  | Block format 0x00 |
75 ### Block Format 0x00 Content
77 Note: addresses relative to start of bootloader block
79 | Start Address | End address | Usage            |
80 | ------------- | ----------- | ---------------- |
81 | 0x01          | 0x01        | Checksum/Hash method |
82 | 0x02          | 0x2F        | Reserved, fill with 0x00 |
83 | 0x30          | 0x3F        | Checksum value, pad with trailing 0x00 |
85 Checksum Hash methods
87 | Value | Meaning          |
88 | ----- | ---------------- |
89 | 0x00  | No checksum.     |
90 | 0x01  | MD5.             |
92 Checksum locations:
94 | Start Address | End address | Usage            |
95 | ------------- | ----------- | ---------------- |
96 | 0x30          | 0x3F        | MD5 hash of firmware section |
98 The bootloader should make no attempt to use any reserved area otherwise this prevents it's future use by the firmware.
100 The bootloader should ensure this block is in RAM when the firmware is loaded.  i.e. copy the entire EXST image.
102 As the reserved area is under control of the build system, not the bootloader, additional information can stored there for use by the firmware or future bootloaders.  Extreme care must be taken not to break the bootloaders ability to load firmware.  Consultation with the developers for any changes to this area is required.
104 ### Example possible future enhancements for the EXST bootloader block
106 * Hardware layout identification - to allow the firmware to identify the hardware, such that IO pins and peripherals can be reserved/initialised.
107 * Alternative hashes/CRCs.